*------------------------------------------------------------------------------------------------------------%	
* Table 6: Estimated spillover from large retailer VMWs
*------------------------------------------------------------------------------------------------------------%	
	* Load nonpolicy firm data
	use using "$data/cb/stacked_nonpolicy_firm_dataset.dta" if balanced_long==1, clear

	drop if trt_exp==4
	keep if inrange(etime, -12, 11)

	* Clean before merge
	rename ln_avg_wage_exact ln_wage_other
	keep ln_wage_other cz etime trt_exp cmp_company_code poaching* feeder* sample_ind estab_id T share_affected mw balanced_* months*

	* Merge with policy firm data
	merge m:1 cz etime trt_exp using "$data/cb/stacked_policy_firm_dataset.dta", nogen keep (3) keepusing(ln_avg_wage_exact)

	global wage ln_avg_wage_exact
	la var ln_avg_wage_exact "log average hourly wage"
	
	* Indicator for post policy
	gen postperiod = etime>=0
	
	* Regress ------------------------------------------------------------------
	eststo clear
  
	* All
	preserve
	keep if sample_ind==1
	qui sum T,d
	local std_T=round(r(sd),.001)
	
	egen T_std=std(T)
	replace T=T_std	
	
	* Generate treatment variable
	gen D = T*postperiod

	eststo c1: ivreghdfe ln_wage_other ($wage = D) if balanced_short == 1 & sample_ind==1, absorb( i.cmp_company_code#i.cz#i.trt_exp i.cmp_company_code##i.trt_exp i.cz##i.trt_exp i.etime##i.trt_exp) cluster(cz) first
		gen keep1 = e(sample) == 1
		estadd local Tstd `std_T': c1
		distinct cz if keep1 == 1
		estadd local Ncz `r(ndistinct)': c1
		distinct cmp_company_code if keep1==1
		estadd local Ncmp `r(ndistinct)': c1		
		estadd local cmpXCZFE "Y": c1
		estadd local MonthFE "Y": c1
	eststo a1: reghdfe ln_wage_other D if keep1 == 1, absorb( i.cmp_company_code#i.cz#i.trt_exp i.cmp_company_code##i.trt_exp i.cz##i.trt_exp i.etime##i.trt_exp) cluster(cz)
	eststo b1: reghdfe $wage D if keep1 == 1, absorb( i.cmp_company_code#i.cz#i.trt_exp i.cmp_company_code##i.trt_exp i.cz##i.trt_exp i.etime##i.trt_exp) cluster(cz)
	restore
	
	* Major
	preserve
	keep if share_affected > .3 & sample_ind==1
	qui sum T,d
	local std_T=round(r(sd),.001)

	egen T_std=std(T)
	replace T=T_std	
	
	* Generate treatment variable
	gen D = T*postperiod

	eststo c2: ivreghdfe ln_wage_other ($wage = D) if share_affected > .3 & sample_ind==1 & balanced_short == 1, absorb( i.cmp_company_code#i.cz#i.trt_exp i.cmp_company_code##i.trt_exp i.cz##i.trt_exp i.etime##i.trt_exp)  cluster(cz) first 
		gen keep2 = e(sample) == 1
		estadd local Tstd `std_T': c2
		distinct cz if keep2 == 1
		estadd local Ncz `r(ndistinct)': c2
		distinct cmp_company_code if keep2==1
		estadd local Ncmp `r(ndistinct)': c2		
		estadd local cmpXCZFE "Y": c2
		estadd local MonthFE "Y": c2
	eststo a2: reghdfe ln_wage_other D if share_affected > .3 & keep2 == 1, absorb( i.cmp_company_code#i.cz#i.trt_exp i.cmp_company_code##i.trt_exp i.cz##i.trt_exp i.etime##i.trt_exp) cluster(cz)
	eststo b2: reghdfe $wage D if share_affected > .3 & keep2 == 1, absorb( i.cmp_company_code#i.cz#i.trt_exp i.cmp_company_code##i.trt_exp i.cz##i.trt_exp i.etime##i.trt_exp) cluster(cz)
	restore
	
	* $15
	preserve
	keep if  mw==15 & sample_ind==1
	qui sum T,d
	local std_T=round(r(sd),.001)

	egen T_std=std(T)
	replace T=T_std	
	
	* Generate treatment variable
	gen D = T*postperiod

	eststo c3: ivreghdfe ln_wage_other ($wage = D) if mw==15 & sample_ind==1 & balanced_short == 1, absorb( i.cmp_company_code#i.cz#i.trt_exp i.cmp_company_code##i.trt_exp i.cz##i.trt_exp i.etime##i.trt_exp) cluster(cz) first 
		gen keep3 = e(sample) == 1
		estadd local Tstd `std_T': c3
		distinct cz if keep3 == 1
		estadd local Ncz `r(ndistinct)': c3
		distinct cmp_company_code if keep3==1
		estadd local Ncmp `r(ndistinct)': c3	
		estadd local cmpXCZFE "Y": c3
		estadd local MonthFE "Y": c3
	eststo a3: reghdfe ln_wage_other D if mw==15 & keep3 == 1 , absorb( i.cmp_company_code#i.cz#i.trt_exp i.cmp_company_code##i.trt_exp i.cz##i.trt_exp i.etime##i.trt_exp) cluster(cz)
	eststo b3: reghdfe $wage D if mw==15 & keep3 == 1, absorb( i.cmp_company_code#i.cz#i.trt_exp i.cmp_company_code##i.trt_exp i.cz##i.trt_exp i.etime##i.trt_exp) cluster(cz)
	restore
	
	* $15 & poaching establishment
	preserve
	keep if  mw==15 &  (poaching_estab==1| feeder_estab==1) 
	qui sum T,d
	local std_T=round(r(sd),.001)
	egen T_std=std(T)
	replace T=T_std	
	
	* Generate treatment variable
	gen D = T*postperiod

	eststo c4: ivreghdfe ln_wage_other ($wage = D) if mw==15 &  (poaching_estab==1| feeder_estab==1) & balanced_short == 1, absorb(i.cmp_company_code#i.cz#i.trt_exp i.cmp_company_code##i.trt_exp i.cz##i.trt_exp i.etime##i.trt_exp) cluster(cz) first 
		gen keep4 = e(sample) == 1
		estadd local Tstd `std_T': c4
		distinct cz if keep4 == 1
		estadd local Ncz `r(ndistinct)': c4
		distinct cmp_company_code if keep4==1
		estadd local Ncmp `r(ndistinct)': c4	
		estadd local cmpXCZFE "Y": c4
		estadd local MonthFE "Y": c4
	eststo a4: reghdfe ln_wage_other D if mw==15 &  keep4 == 1, absorb(i.cmp_company_code#i.cz#i.trt_exp i.cmp_company_code##i.trt_exp i.cz##i.trt_exp i.etime##i.trt_exp) cluster(cz)
	eststo b4: reghdfe $wage D if mw==15 & keep4 == 1, absorb(i.cmp_company_code#i.cz#i.trt_exp i.cmp_company_code##i.trt_exp i.cz##i.trt_exp i.etime##i.trt_exp) cluster(cz)
	restore 
	
	* Build table --------------------------------------------------------------
	#d ;
	esttab a* 
			using "$figures_tables/table6_did_spillover_estimates.tex",  
			replace label fragment
			nolines  
			prehead("\begin{threeparttable} \begin{tabular}{lcccc} \toprule \toprule \\ Indep. Var.: Large Retailer Gap X 1(Post)") 
			posthead("\cmidrule{2-5}" "Dep. Var.:  & & & & \\") 
			booktabs								
			nonumbers 
			mtitles("All events" "Major events"  "\\$15 events" "\\$15: pos. flows") 
			collabels(none)  
			cells(b(star fmt(%9.4f)) se(par fmt(%9.4f)) ) 
			starlevels(* 0.1 ** 0.05 *** 0.01) 						
			keep(D)   
			coeflabel(D "Log avg. wage, non-policy") 
			noobs
			substitute({table} {threeparttable}) 	
	;
	esttab b*
			using "$figures_tables/table6_did_spillover_estimates.tex",  
			append fragment
			nolines  
			prehead("\\") posthead("") 
			booktabs								
			nonumbers 
			nomtitles 
			collabels(none)  
			cells(b(star fmt(%9.4f)) se(par fmt(%9.4f)) ) 
			starlevels(* 0.1 ** 0.05 *** 0.01) 						
			keep(D)   
			coeflabel(D "Log avg. wage, policy") 
			noobs
			substitute({table} {threeparttable}) 	
	;
	esttab c*
			using "$figures_tables/table6_did_spillover_estimates.tex",  
			append fragment
			nolines  
			prehead("\\") posthead("") 
			booktabs								
			nonumbers 
			nomtitles 
			collabels(none)  
			cells(b(star fmt(%9.4f)) se(par fmt(%9.4f)) ci(par fmt(%9.4f)) ) 
			starlevels(* 0.1 ** 0.05 *** 0.01) 						
			keep(ln_avg_wage_exact)   
			coeflabel($wage "Cross-employer wage elasticity") 
			stats(
				N Ncz Ncmp Tstd cmpXCZFE MonthFE, 
				fmt(%12.0gc) 
				label("Obs" "CZs" "Firms" "St. dev. large retailer gap" "Company X CZ FEs" "Month from event FEs")
			)
			prefoot(\midrule) 
			postfoot(\bottomrule \bottomrule \end{tabular} \end{threeparttable} )
	;
	#d cr	

*------------------------------------------------------------------------------------------------------------%	
* Table D6: Estimated spillover from large retailer VMWs on new hire wages
*------------------------------------------------------------------------------------------------------------%	
	* Load nonpolicy firm data
	use using "$data/cb/stacked_nonpolicy_firm_dataset.dta" if balanced_long==1, clear

	drop if trt_exp==4
	keep if inrange(etime, -12, 11)

	* Set outcome
	global wage ln_avg_wage_bins_nh
	
	* Indicator for post policy
	gen postperiod = etime>=0

	* Regress ------------------------------------------------------------------
	eststo clear

	* All
	preserve
	keep if sample_ind==1
	qui sum T,d
	local std_T=round(r(sd),.001)
	
	egen T_std=std(T)
	replace T=T_std	
	
	* Generate treatment variable
	gen D = T*postperiod
	
	eststo a1: reghdfe $wage D, absorb( i.cmp_company_code#i.cz#i.trt_exp i.cmp_company_code##i.trt_exp i.cz##i.trt_exp i.etime##i.trt_exp) cluster(cz)
		gen keep1 = e(sample) == 1
		estadd local Tstd `std_T': a1
		distinct cz if keep1 == 1
		estadd local Ncz `r(ndistinct)': a1
		distinct cmp_company_code if keep1==1
		estadd local Ncmp `r(ndistinct)': a1	
		estadd local cmpXCZFE "Y": a1
		estadd local MonthFE "Y": a1	
	restore
	
	* Major
	preserve
	keep if share_affected > .3 & sample_ind==1
	qui sum T,d
	local std_T=round(r(sd),.001)

	egen T_std=std(T)
	replace T=T_std	
	
	* Generate treatment variable
	gen D = T*postperiod

	eststo a2: reghdfe $wage D if share_affected > .3, absorb( i.cmp_company_code#i.cz#i.trt_exp i.cmp_company_code##i.trt_exp i.cz##i.trt_exp i.etime##i.trt_exp) cluster(cz)
		gen keep2 = e(sample) == 1
		estadd local Tstd `std_T': a2
		distinct cz if keep2 == 1
		estadd local Ncz `r(ndistinct)': a2
		distinct cmp_company_code if keep2==1
		estadd local Ncmp `r(ndistinct)': a2	
		estadd local cmpXCZFE "Y": a2
		estadd local MonthFE "Y": a2
	restore 
	
	* $15
	preserve
	keep if  mw==15 & sample_ind==1
	qui sum T,d
	local std_T=round(r(sd),.001)

	egen T_std=std(T)
	replace T=T_std	
	
	* Generate treatment variable
	gen D = T*postperiod

	eststo a3: reghdfe $wage D if mw==15, absorb( i.cmp_company_code#i.cz#i.trt_exp i.cmp_company_code##i.trt_exp i.cz##i.trt_exp i.etime##i.trt_exp) cluster(cz)
		gen keep3 = e(sample) == 1
		estadd local Tstd `std_T': a3
		distinct cz if keep3 == 1
		estadd local Ncz `r(ndistinct)': a3
		distinct cmp_company_code if keep3==1
		estadd local Ncmp `r(ndistinct)': a3	
		estadd local cmpXCZFE "Y": a3
		estadd local MonthFE "Y": a3
	restore

	* $15 & poaching establishment
	preserve
	keep if  mw==15 &  (poaching_estab==1| feeder_estab==1) 
	qui sum T,d
	local std_T=round(r(sd),.001)
	egen T_std=std(T)
	replace T=T_std	
	
	* Generate treatment variable
	gen D = T*postperiod

	eststo a4: reghdfe $wage D if mw==15, absorb(i.cmp_company_code#i.cz#i.trt_exp i.cmp_company_code##i.trt_exp i.cz##i.trt_exp i.etime##i.trt_exp) cluster(cz)
		gen keep4 = e(sample) == 1
		estadd local Tstd `std_T': a4
		distinct cz if keep4 == 1
		estadd local Ncz `r(ndistinct)': a4
		distinct cmp_company_code if keep4==1
		estadd local Ncmp `r(ndistinct)': a4	
		estadd local cmpXCZFE "Y": a4
		estadd local MonthFE "Y": a4
	restore 
	
	* Build table --------------------------------------------------------------
	#d ;
	esttab a* 
			using "$figures_tables/appendix/tabled6_did_spillover_estimates_nh_wages.tex",  
			replace label fragment
			nolines  
			prehead("\begin{threeparttable} \begin{tabular}{lcccc} \toprule \toprule \\ Indep. Var.: Large Retailer Gap X 1(Post)") 
			posthead("\cmidrule{2-5}" "Dep. Var.:  & & & & \\") 
			booktabs								
			nonumbers 
			mtitles("All events" "Major events"  "\\$15 events" "\\$15: pos. flows") 
			collabels(none)  
			cells(b(star fmt(%9.3f)) se(par fmt(%9.3f)) ) 
			starlevels(* 0.1 ** 0.05 *** 0.01) 						
			keep(D)   
			coeflabel(D "Log avg. wage, non-policy") 
			stats(
				N Ncz Ncmp Tstd cmpXCZFE MonthFE, 
				fmt(%12.0gc) 
				label("Obs" "CZs" "Firms" "St. dev. large retailer gap" "Company X CZ FEs" "Month from event FEs")
			)
			substitute({table} {threeparttable}) 	
			prefoot(\midrule) 
			postfoot(\bottomrule \bottomrule \end{tabular} \end{threeparttable} )			
	;
	#d cr	
	
*------------------------------------------------------------------------------------------------------------%	
* Table 7: Estimated spillover from large retailer VMWs, positive flows relative to non-positive flows
*------------------------------------------------------------------------------------------------------------%	
	* Load nonpolicy firm data
	use using "$data/cb/stacked_nonpolicy_firm_dataset.dta" if balanced_long==1, clear
	drop if trt_exp==4
	keep if inrange(etime, -12, 11)
	
	* Clean
	keep ln_avg_wage_exact cz etime trt_exp cmp_company_code poaching* feeder* sample_ind estab_id T share_affected mw balanced_* months*
	gen pos_flows_estab = (feeder_estab == 1 | poaching_estab == 1)
	
	* Indicator for post policy
	gen postperiod = etime>=0
	
	* Regress ------------------------------------------------------------------
	eststo clear

	* All
	preserve
	keep if sample_ind==1
	qui sum T,d
	local std_T=round(r(sd),.001)
	
	egen T_std=std(T)
	replace T=T_std	
	
	eststo a1: reghdfe ln_avg_wage_exact c.T#1.postperiod#1.pos_flows_estab c.T#1.postperiod 1.pos_flows_estab#1.postperiod if balanced_short==1 & sample_ind==1, absorb(i.cmp_company_code#i.cz#i.trt_exp i.cmp_company_code##i.trt_exp i.cz##i.trt_exp i.etime##i.trt_exp) cluster(cz)
	estadd local Tstd `std_T': a1
	distinct cz if e(sample) == 1
	estadd local Ncz `r(ndistinct)': a1
	distinct cmp_company_code if e(sample) == 1
	estadd local Ncmp `r(ndistinct)': a1	
	distinct cmp_company_code if e(sample) == 1 & pos_flows_estab==1
	estadd local Ncmp_flows `r(ndistinct)': a1	
	estadd local cmpXCZFE "Y": a1
	estadd local MonthFE "Y": a1
	restore
	
	* Major
	preserve
	keep if share_affected > .3 & sample_ind==1
	qui sum T,d
	local std_T=round(r(sd),.001)

	egen T_std=std(T)
	replace T=T_std	
	
	eststo a2: reghdfe ln_avg_wage_exact c.T#1.postperiod#1.pos_flows_estab c.T#1.postperiod 1.pos_flows_estab#1.postperiod if balanced_short==1 & sample_ind==1 & share_affected>.3, absorb(i.cmp_company_code#i.cz#i.trt_exp i.cmp_company_code##i.trt_exp i.cz##i.trt_exp i.etime##i.trt_exp) cluster(cz)
	estadd local Tstd `std_T': a2
	distinct cz if e(sample) == 1
	estadd local Ncz `r(ndistinct)': a2
	distinct cmp_company_code if e(sample) == 1
	estadd local Ncmp `r(ndistinct)': a2	
	distinct cmp_company_code if e(sample) == 1 & pos_flows_estab==1
	estadd local Ncmp_flows `r(ndistinct)': a2	
	estadd local cmpXCZFE "Y": a2
	estadd local MonthFE "Y": a2	
	restore 
	
	* $15
	preserve
	keep if  mw==15 & sample_ind==1
	qui sum T,d
	local std_T=round(r(sd),.001)

	egen T_std=std(T)
	replace T=T_std	

	eststo a3: reghdfe ln_avg_wage_exact c.T#1.postperiod#1.pos_flows_estab c.T#1.postperiod 1.pos_flows_estab#1.postperiod if balanced_short==1 & sample_ind==1 & mw==15, absorb(i.cmp_company_code#i.cz#i.trt_exp i.cmp_company_code##i.trt_exp i.cz##i.trt_exp i.etime##i.trt_exp) cluster(cz)
	estadd local Tstd `std_T': a3
	distinct cz if e(sample) == 1
	estadd local Ncz `r(ndistinct)': a3
	distinct cmp_company_code if e(sample) == 1
	estadd local Ncmp `r(ndistinct)': a3	
	distinct cmp_company_code if e(sample) == 1 & pos_flows_estab==1
	estadd local Ncmp_flows `r(ndistinct)': a3	
	estadd local cmpXCZFE "Y": a3
	estadd local MonthFE "Y": a3
	restore 
	
	* Build table --------------------------------------------------------------
	#d ;
	esttab a* 
			using "$figures_tables/table7_spillover_pos_flows_heterogeneity.tex",  
			replace label fragment
			nolines  
			prehead("\begin{threeparttable} \begin{tabular}{lccc} \toprule \toprule & \multicolumn{3}{c}{Dep Var: Log average wage, non-policy} \\ Independent variables") 
			posthead("\cmidrule{2-4}") 
			booktabs								
			nonumbers 
			mtitles("All events" "Major events"  "\\$15 events") 
			collabels(none)  
			cells(b(star fmt(%9.4f)) se(par fmt(%9.4f)) ) 
			starlevels(* 0.1 ** 0.05 *** 0.01) 						
			keep(1.po*)   
			coeflabel(1.postperiod#1.pos_flows_estab#c.T "Large retailer gap X 1(Post) X 1(Flows)" 1.postperiod#c.T "Large retailer gap X 1(Post)" 1.pos_flows_estab#1.postperiod "1(Post) X 1(Flows)") 
			stats(
	N Ncz Ncmp Ncmp_flows Tstd cmpXCZFE MonthFE, 
				fmt(%12.0gc) 
				label("Obs" "CZs" "Firms" "Connected firms" "St. dev. large retailer gap" "Company X CZ FEs" "Month from event FEs")
				)
			prefoot(\midrule) 
			postfoot(\bottomrule \bottomrule \end{tabular} \end{threeparttable} )
	;
	#d cr	

*------------------------------------------------------------------------------------------------------------%	
* Table D8: Estimated spillover from large retailer VMWs, positive flows relative to non-positive flows, market gap
*------------------------------------------------------------------------------------------------------------%	
	* Load nonpolicy firm data
	use using "$data/cb/stacked_nonpolicy_firm_dataset.dta" if balanced_long==1, clear
	drop if trt_exp==4
	keep if inrange(etime, -12, 11)
	
	* Clean
	keep ln_avg_wage_exact cz etime trt_exp cmp_company_code poaching* feeder* sample_ind estab_id super_gap T share_affected mw balanced_* months*
	gen pos_flows_estab = (feeder_estab == 1 | poaching_estab == 1)
	
	* Indicator for post policy
	gen postperiod = etime>=0
	
	* Regress ------------------------------------------------------------------
	eststo clear

	* All
	preserve
	keep if sample_ind==1
	qui sum super_gap,d
	local std_T=round(r(sd),.001)
	
	egen sg_std=std(super_gap)
	replace T=sg_std	
	
	eststo a1: reghdfe ln_avg_wage_exact c.T#1.postperiod#1.pos_flows_estab c.T#1.postperiod 1.pos_flows_estab#1.postperiod if balanced_short==1 & sample_ind==1, absorb(i.cmp_company_code#i.cz#i.trt_exp i.cmp_company_code##i.trt_exp i.cz##i.trt_exp i.etime##i.trt_exp) cluster(cz)
	estadd local Tstd `std_T': a1
	distinct cz if e(sample) == 1
	estadd local Ncz `r(ndistinct)': a1
	distinct cmp_company_code if e(sample) == 1
	estadd local Ncmp `r(ndistinct)': a1	
	estadd local cmpXCZFE "Y": a1
	estadd local MonthFE "Y": a1
	restore
	
	* Major
	preserve
	keep if share_affected > .3 & sample_ind==1
	qui sum super_gap,d
	local std_T=round(r(sd),.001)
	
	egen sg_std=std(super_gap)
	replace T=sg_std	
	
	eststo a2: reghdfe ln_avg_wage_exact c.T#1.postperiod#1.pos_flows_estab c.T#1.postperiod 1.pos_flows_estab#1.postperiod if balanced_short==1 & sample_ind==1 & share_affected>.3, absorb(i.cmp_company_code#i.cz#i.trt_exp i.cmp_company_code##i.trt_exp i.cz##i.trt_exp i.etime##i.trt_exp) cluster(cz)
	estadd local Tstd `std_T': a2
	distinct cz if e(sample) == 1
	estadd local Ncz `r(ndistinct)': a2
	distinct cmp_company_code if e(sample) == 1
	estadd local Ncmp `r(ndistinct)': a2	
	estadd local cmpXCZFE "Y": a2
	estadd local MonthFE "Y": a2	
	restore 
	
	* $15
	preserve
	keep if  mw==15 & sample_ind==1
	qui sum super_gap,d
	local std_T=round(r(sd),.001)
	
	egen sg_std=std(super_gap)
	replace T=sg_std	

	eststo a3: reghdfe ln_avg_wage_exact c.T#1.postperiod#1.pos_flows_estab c.T#1.postperiod 1.pos_flows_estab#1.postperiod if balanced_short==1 & sample_ind==1 & mw==15, absorb(i.cmp_company_code#i.cz#i.trt_exp i.cmp_company_code##i.trt_exp i.cz##i.trt_exp i.etime##i.trt_exp) cluster(cz)
	estadd local Tstd `std_T': a3
	distinct cz if e(sample) == 1
	estadd local Ncz `r(ndistinct)': a3
	distinct cmp_company_code if e(sample) == 1
	estadd local Ncmp `r(ndistinct)': a3	
	estadd local cmpXCZFE "Y": a3
	estadd local MonthFE "Y": a3
	restore 
	
	* Build table --------------------------------------------------------------
	#d ;
	esttab a* 
			using "$figures_tables/appendix/tabled8_sg_spillover_pos_flows_heterogeneity.tex",  
			replace label fragment
			nolines  
			prehead("\begin{threeparttable} \begin{tabular}{lccc} \toprule \toprule & \multicolumn{3}{c}{Dep Var: Log average wage, non-policy} \\ Independent variables") 
			posthead(\cmidrule{2-4}) 
			booktabs								
			nonumbers 
			mtitles("All events" "Major events"  "\\$15 events") 
			collabels(none)  
			cells(b(star fmt(%9.5f)) se(par fmt(%9.5f)) ) 
			starlevels(* 0.1 ** 0.05 *** 0.01) 						
			keep(1.po*)   
			coeflabel(1.postperiod#1.pos_flows_estab#c.T "Large retailer gap X 1(Post) X 1(Flows)" 1.postperiod#c.T "Large retailer gap X 1(Post)" 1.pos_flows_estab#1.postperiod "1(Post) X 1(Flows)") 
			stats(
	N Ncz Ncmp Tstd cmpXCZFE MonthFE, 
				fmt(%12.0gc) 
				label("Obs" "CZs" "Firms" "St. dev. large retailer gap" "Company X CZ FEs" "Month from event FEs")
				)
			prefoot(\midrule) 
			postfoot(\bottomrule \bottomrule \end{tabular} \end{threeparttable} )
	;
	#d cr	
					
*------------------------------------------------------------------------------------------------------------%	
* Table D7: Estimated spillover from large retailer VMWs: Heterogeneity by employment share and positive flows
*------------------------------------------------------------------------------------------------------------%	
	* Load nonpolicy firm data
	use if trt_exp!=4 & inrange(etime, -12, 11) & balanced_long==1 using "$data/cb/stacked_nonpolicy_firm_dataset.dta", clear
	
	* Clean
	gen employment_share_med = .
	levelsof trt_exp, local(exp)
	foreach experiment in `exp' {
		sum employment_share if trt_exp==`experiment', d
		replace employment_share_med = employment_share > `r(p50)' if trt_exp==`experiment'
		di `r(p50)'
	}
	keep ln_avg_wage_exact cz etime trt_exp cmp_company_code poaching* feeder* sample_ind estab_id T share_affected mw balanced_* months* employment_share_med employment_share employment_share_decile employment_share_q_all_decile
	gen pos_flows_estab = (feeder_estab == 1 | poaching_estab == 1)
	
	* Indicator for post policy
	gen postperiod = etime>=0	
	
	* Regress ------------------------------------------------------------------
	eststo clear

	* All
	preserve
	keep if sample_ind==1 & employment_share_q_all_decile<7
	qui sum T,d
	local std_T=round(r(sd),.001)
	
	egen T_std=std(T)
	replace T=T_std	
	
	eststo a1: reghdfe ln_avg_wage_exact c.T#1.postperiod#1.pos_flows_estab c.T#1.postperiod 1.pos_flows_estab#1.postperiod if employment_share_decile<7 & sample_ind==1 , absorb(i.cmp_company_code#i.cz#i.trt_exp i.cmp_company_code##i.trt_exp i.cz##i.trt_exp i.etime##i.trt_exp) cluster(cz)
	estadd local Tstd `std_T': a1
	distinct cz if e(sample) == 1
	estadd local Ncz `r(ndistinct)': a1
	distinct cmp_company_code if e(sample) == 1
	estadd local Ncmp `r(ndistinct)': a1	
	sum employment_share if e(sample) == 1
	local temp: di %4.3f `r(mean)'
	estadd local MeanEmpShare `temp'
	estadd local cmpXCZFE "Y": a1
	estadd local MonthFE "Y": a1
	restore
	
	preserve
	keep if sample_ind==1 & employment_share_q_all_decile>=7
	qui sum T,d
	local std_T=round(r(sd),.001)
	
	egen T_std=std(T)
	replace T=T_std	

	eststo b1: reghdfe ln_avg_wage_exact c.T#1.postperiod#1.pos_flows_estab c.T#1.postperiod 1.pos_flows_estab#1.postperiod if employment_share_decile>=7 & sample_ind==1, absorb(i.cmp_company_code#i.cz#i.trt_exp i.cmp_company_code##i.trt_exp i.cz##i.trt_exp i.etime##i.trt_exp) cluster(cz)
	estadd local Tstd `std_T': b1
	distinct cz if e(sample) == 1
	estadd local Ncz `r(ndistinct)': b1
	distinct cmp_company_code if e(sample) == 1
	estadd local Ncmp `r(ndistinct)': b1	
	sum employment_share if e(sample) == 1
	local temp: di %4.3f `r(mean)'
	estadd local MeanEmpShare `temp'
	estadd local cmpXCZFE "Y": b1
	estadd local MonthFE "Y": b1
	restore
	
	* Major
	preserve
	keep if sample_ind==1 & share_affected > .3 & employment_share_q_all_decile<7
	qui sum T,d
	local std_T=round(r(sd),.001)
	
	egen T_std=std(T)
	replace T=T_std	

	eststo a2: reghdfe ln_avg_wage_exact c.T#1.postperiod#1.pos_flows_estab c.T#1.postperiod 1.pos_flows_estab#1.postperiod if employment_share_decile<7 & sample_ind==1 & share_affected > .3, absorb(i.cmp_company_code#i.cz#i.trt_exp i.cmp_company_code##i.trt_exp i.cz##i.trt_exp i.etime##i.trt_exp) cluster(cz)
	estadd local Tstd `std_T': a2
	distinct cz if e(sample) == 1
	estadd local Ncz `r(ndistinct)': a2
	distinct cmp_company_code if e(sample) == 1
	estadd local Ncmp `r(ndistinct)': a2	
	sum employment_share if e(sample) == 1
	local temp: di %4.3f `r(mean)'
	estadd local MeanEmpShare `temp'
	estadd local cmpXCZFE "Y": a2
	estadd local MonthFE "Y": a2
	restore
	
	preserve
	keep if sample_ind==1 & share_affected > .3 & employment_share_q_all_decile>=7
	qui sum T,d
	local std_T=round(r(sd),.001)
	
	egen T_std=std(T)
	replace T=T_std	
	
	eststo b2: reghdfe ln_avg_wage_exact c.T#1.postperiod#1.pos_flows_estab c.T#1.postperiod 1.pos_flows_estab#1.postperiod if employment_share_decile>=7 & sample_ind==1 & share_affected > .3, absorb(i.cmp_company_code#i.cz#i.trt_exp i.cmp_company_code##i.trt_exp i.cz##i.trt_exp i.etime##i.trt_exp) cluster(cz)
	estadd local Tstd `std_T': b2
	distinct cz if e(sample) == 1
	estadd local Ncz `r(ndistinct)': b2
	distinct cmp_company_code if e(sample) == 1
	estadd local Ncmp `r(ndistinct)': b2	
	sum employment_share if e(sample) == 1
	local temp: di %4.3f `r(mean)'
	estadd local MeanEmpShare `temp'
	estadd local cmpXCZFE "Y": b2
	estadd local MonthFE "Y": b2
	restore
	
	* $15
	preserve
	keep if sample_ind==1 & mw == 15 & employment_share_q_all_decile<7
	qui sum T,d
	local std_T=round(r(sd),.001)
	
	egen T_std=std(T)
	replace T=T_std	

	eststo a3: reghdfe ln_avg_wage_exact c.T#1.postperiod#1.pos_flows_estab c.T#1.postperiod 1.pos_flows_estab#1.postperiod if employment_share_decile<7 & sample_ind==1 & mw == 15, absorb(i.cmp_company_code#i.cz#i.trt_exp i.cmp_company_code##i.trt_exp i.cz##i.trt_exp i.etime##i.trt_exp) cluster(cz)
	estadd local Tstd `std_T': a3
	distinct cz if e(sample) == 1
	estadd local Ncz `r(ndistinct)': a3
	distinct cmp_company_code if e(sample) == 1
	estadd local Ncmp `r(ndistinct)': a3	
	sum employment_share if e(sample) == 1
	local temp: di %4.3f `r(mean)'
	estadd local MeanEmpShare `temp'
	estadd local cmpXCZFE "Y": a3
	estadd local MonthFE "Y": a3
	restore
	
	preserve
	keep if sample_ind==1 & mw == 15 & employment_share_q_all_decile>=7
	qui sum T,d
	local std_T=round(r(sd),.001)
	
	egen T_std=std(T)
	replace T=T_std	

	eststo b3: reghdfe ln_avg_wage_exact c.T#1.postperiod#1.pos_flows_estab c.T#1.postperiod 1.pos_flows_estab#1.postperiod if employment_share_decile>=7 & sample_ind==1 & mw == 15, absorb(i.cmp_company_code#i.cz#i.trt_exp i.cmp_company_code##i.trt_exp i.cz##i.trt_exp i.etime##i.trt_exp) cluster(cz)
	estadd local Tstd `std_T': b3
	distinct cz if e(sample) == 1
	estadd local Ncz `r(ndistinct)': b3
	distinct cmp_company_code if e(sample) == 1
	estadd local Ncmp `r(ndistinct)': b3	
	sum employment_share if e(sample) == 1
	local temp: di %4.3f `r(mean)'
	estadd local MeanEmpShare `temp'
	estadd local cmpXCZFE "Y": b3
	estadd local MonthFE "Y": b3
	restore
	
	* Build table --------------------------------------------------------------
	#d ;
	esttab a* b*
			using "$figures_tables/tabled7_spillover_emp_share_pos_flows_heterogeneity.tex",  
			replace label fragment
			nolines  
			prehead("\begin{threeparttable} \begin{tabular}{lcccccc} \toprule \toprule & \multicolumn{6}{c}{Dep Var: Log average wage, non-policy} \\ & \multicolumn{3}{c}{Low Emp. Share} & \multicolumn{3}{c}{High Emp. Share} \\ Independent variables") 
			posthead(\cmidrule(lr){2-4} \cmidrule(lr){5-7}) 
			booktabs								
			nonumbers 
			mtitles("All events" "Major events"  "\\$15 events" "All events" "Major events"  "\\$15 events") 
			collabels(none)  
			cells(b(star fmt(%9.5f)) se(par fmt(%9.5f)) ) 
			starlevels(* 0.1 ** 0.05 *** 0.01) 						
			keep(1.po*)   
			coeflabel(1.postperiod#1.pos_flows_estab#c.T "Large retailer gap X 1(Post) X 1(Flows)" 1.postperiod#c.T "Large retailer gap X 1(Post)" 1.pos_flows_estab#1.postperiod "1(Post) X 1(Flows)") 
			stats(
	N Ncz Ncmp Tstd MeanEmpShare cmpXCZFE MonthFE, 
				fmt(%12.0gc) 
				label("Obs" "CZs" "Firms" "St. dev. large retailer gap" "Mean policy emp. share" "Company X CZ FEs" "Month from event FEs")
				)
			prefoot(\midrule) 
			postfoot(\bottomrule \bottomrule \end{tabular} \end{threeparttable} )
	;
	#d cr				

*------------------------------------------------------------------------------------------------------------%	
* Table 9: Estimated spillover from large retailer VMWs, market gap
*------------------------------------------------------------------------------------------------------------%	
	* Load nonpolicy firm data
	use using "$data/cb/stacked_nonpolicy_firm_dataset.dta" if balanced_long==1, clear

	drop if trt_exp==4
	keep if inrange(etime, -12, 11)

	* Clean before merge
	rename ln_avg_wage_exact ln_wage_other
	keep ln_wage_other cz etime trt_exp cmp_company_code poaching* feeder* sample_ind estab_id T share_affected mw balanced_* months* super_gap

	* Merge with policy firm data
	merge m:1 cz etime trt_exp using "$data/cb/stacked_policy_firm_dataset.dta", nogen keep (3) keepusing(ln_avg_wage_exact)
	
	global wage ln_avg_wage_exact
	la var ln_avg_wage_exact "log average hourly wage"

	* Indicator for post policy
	gen postperiod = etime>=0
	
	* Regress ------------------------------------------------------------------
	eststo clear
  
	* All
	preserve
	keep if sample_ind==1
	qui sum super_gap,d
	local std_T=round(r(sd),.001)
	
	egen sg_std=std(super_gap)
	replace T=sg_std	
	
	* Generate treatment variable
	gen D = T*postperiod


	eststo a1: reghdfe ln_wage_other D if balanced_short == 1 & sample_ind==1, absorb( i.cmp_company_code#i.cz#i.trt_exp i.cmp_company_code##i.trt_exp i.cz##i.trt_exp i.etime##i.trt_exp) cluster(cz)
		gen keep1 = e(sample) == 1
	eststo b1: reghdfe $wage D if keep1 == 1, absorb( i.cmp_company_code#i.cz#i.trt_exp i.cmp_company_code##i.trt_exp i.cz##i.trt_exp i.etime##i.trt_exp) cluster(cz)
		estadd local Tstd `std_T': b1
		distinct cz if keep1 == 1
		estadd local Ncz `r(ndistinct)': b1
		distinct cmp_company_code if keep1 == 1
		estadd local Ncmp `r(ndistinct)': b1	
		estadd local cmpXCZFE "Y": b1
		estadd local MonthFE "Y": b1
	restore
	
	* Major
	preserve
	keep if share_affected > .3 & sample_ind==1
	qui sum super_gap,d
	local std_T=round(r(sd),.001)

	egen sg_std=std(super_gap)
	replace T=sg_std	
	
	* Generate treatment variable
	gen D = T*postperiod

	eststo a2: reghdfe ln_wage_other D if share_affected > .3 & sample_ind==1 & balanced_short == 1, absorb( i.cmp_company_code#i.cz#i.trt_exp i.cmp_company_code##i.trt_exp i.cz##i.trt_exp i.etime##i.trt_exp) cluster(cz)
		gen keep2 = e(sample) == 1
	eststo b2: reghdfe $wage D if share_affected > .3 & keep2 == 1, absorb( i.cmp_company_code#i.cz#i.trt_exp i.cmp_company_code##i.trt_exp i.cz##i.trt_exp i.etime##i.trt_exp) cluster(cz)
		estadd local Tstd `std_T': b2
		distinct cz if keep2 == 1
		estadd local Ncz `r(ndistinct)': b2
		distinct cmp_company_code if keep2 == 1
		estadd local Ncmp `r(ndistinct)': b2	
		estadd local cmpXCZFE "Y": b2
		estadd local MonthFE "Y": b2
	restore
	
	* $15
	preserve
	keep if  mw==15 & sample_ind==1
	qui sum super_gap,d
	local std_T=round(r(sd),.001)

	egen sg_std=std(super_gap)
	replace T=sg_std	
	
	* Generate treatment variable
	gen D = T*postperiod

	eststo a3: reghdfe ln_wage_other D if mw==15 & sample_ind==1 & balanced_short == 1, absorb( i.cmp_company_code#i.cz#i.trt_exp i.cmp_company_code##i.trt_exp i.cz##i.trt_exp i.etime##i.trt_exp) cluster(cz)
		gen keep3 = e(sample) == 1
	eststo b3: reghdfe $wage D if mw==15 & keep3 == 1, absorb( i.cmp_company_code#i.cz#i.trt_exp i.cmp_company_code##i.trt_exp i.cz##i.trt_exp i.etime##i.trt_exp) cluster(cz)
		estadd local Tstd `std_T': b3
		distinct cz if keep3 == 1
		estadd local Ncz `r(ndistinct)': b3
		distinct cmp_company_code if keep3 == 1
		estadd local Ncmp `r(ndistinct)': b3	
		estadd local cmpXCZFE "Y": b3
		estadd local MonthFE "Y": b3
	restore
	
	* Poaching establishment
	preserve
	keep if mw==15 & (poaching_estab==1| feeder_estab==1) 
	qui sum super_gap,d
	local std_T=round(r(sd),.001)
	egen sg_std=std(super_gap)
	replace T=sg_std	
	
	* Generate treatment variable
	gen D = T*postperiod

	eststo a4: reghdfe ln_wage_other D if mw==15 & (poaching_estab==1| feeder_estab==1) & balanced_short == 1, absorb(i.cmp_company_code#i.cz#i.trt_exp i.cmp_company_code##i.trt_exp i.cz##i.trt_exp i.etime##i.trt_exp) cluster(cz)
		gen keep4 = e(sample) == 1
	eststo b4: reghdfe $wage D if keep4 == 1, absorb(i.cmp_company_code#i.cz#i.trt_exp i.cmp_company_code##i.trt_exp i.cz##i.trt_exp i.etime##i.trt_exp) cluster(cz)
		estadd local Tstd `std_T': b4
		distinct cz if keep4 == 1
		estadd local Ncz `r(ndistinct)': b4
		distinct cmp_company_code if keep4 == 1
		estadd local Ncmp `r(ndistinct)': b4	
		estadd local cmpXCZFE "Y": b4
		estadd local MonthFE "Y": b4		
	restore 
	
	* Build table --------------------------------------------------------------
	#d ;
	esttab a* 
			using "$figures_tables/table9_did_sg_spillover_estimates.tex",  
			replace label fragment
			nolines  
			prehead("\begin{threeparttable} \begin{tabular}{lcccc} \toprule \toprule \\ Indep. Var.: Market Gap X 1(Post)") 
			posthead("\cmidrule{2-5}" "Dep. Var.:  & & & & \\") 
			booktabs								
			nonumbers 
			mtitles("All events" "Major events"  "\\$15 events" "\$15: pos. flows") 
			collabels(none)  
			cells(b(star fmt(%9.4f)) se(par fmt(%9.4f)) ) 
			starlevels(* 0.1 ** 0.05 *** 0.01) 						
			keep(D)   
			coeflabel(D "Log avg. wage, non-policy") 
			noobs
			substitute({table} {threeparttable}) 	
	;
	esttab b*
			using "$figures_tables/table9_did_sg_spillover_estimates.tex",  
			append fragment
			nolines  
			prehead("\\") posthead("") 
			booktabs								
			nonumbers 
			nomtitles 
			collabels(none)  
			cells(b(star fmt(%9.4f)) se(par fmt(%9.4f)) ) 
			starlevels(* 0.1 ** 0.05 *** 0.01) 						
			keep(D)   
			coeflabel(D "Log avg. wage, policy") 
			stats(
				N Ncz Ncmp Tstd cmpXCZFE MonthFE, 
				fmt(%12.0gc) 
				label("Obs" "CZs" "Firms" "St. dev. market gap" "Company X CZ FEs" "Month from event FEs")
			)
			prefoot(\midrule) 
			postfoot(\bottomrule \bottomrule \end{tabular} \end{threeparttable} )
	;
	#d cr	
	
*------------------------------------------------------------------------------------------------------------%	
* Table D10: Estimated spillover from large retailer VMWs, market gap based on connected industry estabs
*------------------------------------------------------------------------------------------------------------%	
	* Load nonpolicy firm data
	use using "$data/cb/stacked_nonpolicy_firm_dataset.dta" if balanced_long==1, clear

	drop if trt_exp==4
	keep if inrange(etime, -12, 11)

	* Clean before merge
	rename ln_avg_wage_exact ln_wage_other
	keep ln_wage_other cz etime trt_exp cmp_company_code poaching* feeder* sample_ind estab_id T share_affected mw balanced_* months* super_gap* employment_share

	* Merge with policy firm data
	merge m:1 cz etime trt_exp using "$data/cb/stacked_policy_firm_dataset.dta", nogen keep (3) keepusing(ln_avg_wage_exact)
	
	global wage ln_avg_wage_exact
	la var ln_avg_wage_exact "log average hourly wage"

	* Indicator for post policy
	gen postperiod = etime>=0
	
	* Regress ------------------------------------------------------------------
	eststo clear
  
	* All
	preserve
	keep if sample_ind==1
	qui sum super_gap_ind,d
	local std_T=round(r(sd),.001)
	
	egen sg_std=std(super_gap_ind)
	replace T=sg_std	
	
	* Generate treatment variable
	gen D = T*postperiod

	eststo a1: reghdfe ln_wage_other D if balanced_short == 1 & sample_ind==1, absorb( i.cmp_company_code#i.cz#i.trt_exp i.cmp_company_code##i.trt_exp i.cz##i.trt_exp i.etime##i.trt_exp) cluster(cz)
		gen keep1 = e(sample) == 1
	eststo b1: reghdfe $wage D if keep1 == 1, absorb( i.cmp_company_code#i.cz#i.trt_exp i.cmp_company_code##i.trt_exp i.cz##i.trt_exp i.etime##i.trt_exp) cluster(cz)
		estadd local Tstd `std_T': b1
		distinct cz if keep1 == 1
		estadd local Ncz `r(ndistinct)': b1
		distinct cmp_company_code if keep1 == 1
		estadd local Ncmp `r(ndistinct)': b1	
		estadd local cmpXCZFE "Y": b1
		estadd local MonthFE "Y": b1
	restore
	
	* Major
	preserve
	keep if share_affected > .3 & sample_ind==1
	qui sum super_gap_ind,d
	local std_T=round(r(sd),.001)

	egen sg_std=std(super_gap_ind)
	replace T=sg_std	
	
	* Generate treatment variable
	gen D = T*postperiod

	eststo a2: reghdfe ln_wage_other D if share_affected > .3 & sample_ind==1 & balanced_short == 1, absorb( i.cmp_company_code#i.cz#i.trt_exp i.cmp_company_code##i.trt_exp i.cz##i.trt_exp i.etime##i.trt_exp) cluster(cz)
		gen keep2 = e(sample) == 1
	eststo b2: reghdfe $wage D if share_affected > .3 & keep2 == 1, absorb( i.cmp_company_code#i.cz#i.trt_exp i.cmp_company_code##i.trt_exp i.cz##i.trt_exp i.etime##i.trt_exp) cluster(cz)
		estadd local Tstd `std_T': b2
		distinct cz if keep2 == 1
		estadd local Ncz `r(ndistinct)': b2
		distinct cmp_company_code if keep2 == 1
		estadd local Ncmp `r(ndistinct)': b2	
		estadd local cmpXCZFE "Y": b2
		estadd local MonthFE "Y": b2
	restore
	
	* $15
	preserve
	keep if  mw==15 & sample_ind==1
	qui sum super_gap_ind,d
	local std_T=round(r(sd),.001)

	egen sg_std=std(super_gap_ind)
	replace T=sg_std	
	
	* Generate treatment variable
	gen D = T*postperiod

	eststo a3: reghdfe ln_wage_other D if mw==15 & sample_ind==1 & balanced_short == 1, absorb( i.cmp_company_code#i.cz#i.trt_exp i.cmp_company_code##i.trt_exp i.cz##i.trt_exp i.etime##i.trt_exp) cluster(cz)
		gen keep3 = e(sample) == 1
	eststo b3: reghdfe $wage D if mw==15 & keep3 == 1, absorb( i.cmp_company_code#i.cz#i.trt_exp i.cmp_company_code##i.trt_exp i.cz##i.trt_exp i.etime##i.trt_exp) cluster(cz)
		estadd local Tstd `std_T': b3
		distinct cz if keep3 == 1
		estadd local Ncz `r(ndistinct)': b3
		distinct cmp_company_code if keep3 == 1
		estadd local Ncmp `r(ndistinct)': b3	
		estadd local cmpXCZFE "Y": b3
		estadd local MonthFE "Y": b3
	restore
	
	* Poaching establishment
	preserve
	keep if mw==15 & (poaching_estab==1| feeder_estab==1) 
	qui sum super_gap_ind,d
	local std_T=round(r(sd),.001)
	egen sg_std=std(super_gap_ind)
	replace T=sg_std	
	
	* Generate treatment variable
	gen D = T*postperiod

	eststo a4: reghdfe ln_wage_other D if mw==15 & (poaching_estab==1| feeder_estab==1) & balanced_short == 1, absorb(i.cmp_company_code#i.cz#i.trt_exp i.cmp_company_code##i.trt_exp i.cz##i.trt_exp i.etime##i.trt_exp) cluster(cz)
		gen keep4 = e(sample) == 1
	eststo b4: reghdfe $wage D if keep4 == 1, absorb(i.cmp_company_code#i.cz#i.trt_exp i.cmp_company_code##i.trt_exp i.cz##i.trt_exp i.etime##i.trt_exp) cluster(cz)
		estadd local Tstd `std_T': b4
		distinct cz if keep4 == 1
		estadd local Ncz `r(ndistinct)': b4
		distinct cmp_company_code if keep4 == 1
		estadd local Ncmp `r(ndistinct)': b4	
		estadd local cmpXCZFE "Y": b4
		estadd local MonthFE "Y": b4		
	restore 
	
	* Build table --------------------------------------------------------------
	#d ;
	esttab a* 
			using "$figures_tables/tabled10_did_sgi_spillover_estimates.tex",  
			replace label fragment
			nolines  
			prehead("\begin{threeparttable} \begin{tabular}{lcccc} \toprule \toprule \\ Indep. Var.: Market Gap (Connected Ind.) X 1(Post)") 
			posthead("\cmidrule{2-5}" "Dep. Var.:  & & & & \\") 
			booktabs								
			nonumbers 
			mtitles("All events" "Major events"  "\\$15 events" "\$15: pos. flows") 
			collabels(none)  
			cells(b(star fmt(%9.4f)) se(par fmt(%9.4f)) ) 
			starlevels(* 0.1 ** 0.05 *** 0.01) 						
			keep(D)   
			coeflabel(D "Log avg. wage, non-policy") 
			noobs
			substitute({table} {threeparttable}) 	
	;
	esttab b*
			using "$figures_tables/tabled10_did_sgi_spillover_estimates.tex",  
			append fragment
			nolines  
			prehead("\\") posthead("") 
			booktabs								
			nonumbers 
			nomtitles 
			collabels(none)  
			cells(b(star fmt(%9.4f)) se(par fmt(%9.4f)) ) 
			starlevels(* 0.1 ** 0.05 *** 0.01) 						
			keep(D)   
			coeflabel(D "Log avg. wage, policy") 
			stats(
				N Ncz Ncmp Tstd cmpXCZFE MonthFE, 
				fmt(%12.0gc) 
				label("Obs" "CZs" "Firms" "St. dev. market gap (connected ind)" "Company X CZ FEs" "Month from event FEs")
			)
			prefoot(\midrule) 
			postfoot(\bottomrule \bottomrule \end{tabular} \end{threeparttable} )
	;
	#d cr	
	
*------------------------------------------------------------------------------------------------------------%	
* Table D8: Estimated spillover from large retailer VMWs on new hire wages, market gap
*------------------------------------------------------------------------------------------------------------%	
	* Load nonpolicy firm data
	use using "$data/cb/stacked_nonpolicy_firm_dataset.dta" if balanced_long==1, clear

	drop if trt_exp==4
	keep if inrange(etime, -12, 11)

	* Set outcome
	global wage ln_avg_wage_bins_nh
	
	* Indicator for post policy
	gen postperiod = etime>=0

	* Regress ------------------------------------------------------------------
	eststo clear

	* All
	preserve
	keep if sample_ind==1
	qui sum super_gap,d
	local std_T=round(r(sd),.001)
	
	egen sg_std=std(super_gap)
	replace T=sg_std	
	
	* Generate treatment variable
	gen D = T*postperiod
	
	eststo a1: reghdfe $wage D, absorb( i.cmp_company_code#i.cz#i.trt_exp i.cmp_company_code##i.trt_exp i.cz##i.trt_exp i.etime##i.trt_exp) cluster(cz)
		gen keep1 = e(sample) == 1
		estadd local Tstd `std_T': a1
		distinct cz if keep1 == 1
		estadd local Ncz `r(ndistinct)': a1
		distinct cmp_company_code if keep1 == 1
		estadd local Ncmp `r(ndistinct)': a1	
		estadd local cmpXCZFE "Y": a1
		estadd local MonthFE "Y": a1	
	restore
	
	* Major
	preserve
	keep if share_affected > .3 & sample_ind==1
	qui sum super_gap,d
	local std_T=round(r(sd),.001)

	egen sg_std=std(super_gap)
	replace T=sg_std	
	
	* Generate treatment variable
	gen D = T*postperiod

	eststo a2: reghdfe $wage D if share_affected > .3, absorb( i.cmp_company_code#i.cz#i.trt_exp i.cmp_company_code##i.trt_exp i.cz##i.trt_exp i.etime##i.trt_exp) cluster(cz)
		gen keep2 = e(sample) == 1
		estadd local Tstd `std_T': a2
		distinct cz if keep2 == 1
		estadd local Ncz `r(ndistinct)': a2
		distinct cmp_company_code if keep2 == 1
		estadd local Ncmp `r(ndistinct)': a2	
		estadd local cmpXCZFE "Y": a2
		estadd local MonthFE "Y": a2
	restore 
	
	* $15
	preserve
	keep if  mw==15 & sample_ind==1
	qui sum super_gap,d
	local std_T=round(r(sd),.001)

	egen sg_std=std(super_gap)
	replace T=sg_std	
	
	* Generate treatment variable
	gen D = T*postperiod

	eststo a3: reghdfe $wage D if mw==15, absorb( i.cmp_company_code#i.cz#i.trt_exp i.cmp_company_code##i.trt_exp i.cz##i.trt_exp i.etime##i.trt_exp) cluster(cz)
		gen keep3 = e(sample) == 1
		estadd local Tstd `std_T': a3
		distinct cz if keep3 == 1
		estadd local Ncz `r(ndistinct)': a3
		distinct cmp_company_code if keep3 == 1
		estadd local Ncmp `r(ndistinct)': a3	
		estadd local cmpXCZFE "Y": a3
		estadd local MonthFE "Y": a3
	restore

	* $15 & poaching establishment
	preserve
	keep if  mw==15 &  (poaching_estab==1| feeder_estab==1) 
	qui sum super_gap,d
	local std_T=round(r(sd),.001)
	egen sg_std=std(super_gap)
	replace T=sg_std	
	
	* Generate treatment variable
	gen D = T*postperiod

	eststo a4: reghdfe $wage D if mw==15, absorb(i.cmp_company_code#i.cz#i.trt_exp i.cmp_company_code##i.trt_exp i.cz##i.trt_exp i.etime##i.trt_exp) cluster(cz)
		gen keep4 = e(sample) == 1
		estadd local Tstd `std_T': a4
		distinct cz if keep4 == 1
		estadd local Ncz `r(ndistinct)': a4
		distinct cmp_company_code if keep4 == 1
		estadd local Ncmp `r(ndistinct)': a4	
		estadd local cmpXCZFE "Y": a4
		estadd local MonthFE "Y": a4
	restore 
	
	* Build table --------------------------------------------------------------
	#d ;
	esttab a* 
			using "$figures_tables/appendix/tabled8_did_sg_spillover_estimates_nh_wages.tex",  
			replace label fragment
			nolines  
			prehead("\begin{threeparttable} \begin{tabular}{lcccc} \toprule \toprule \\ Indep. Var.: Market Gap X 1(Post)") 
			posthead("\cmidrule{2-5}" "Dep. Var.:  & & & & \\") 
			booktabs								
			nonumbers 
			mtitles("All events" "Major events"  "\\$15 events" "\\$15: pos. flows") 
			collabels(none)  
			cells(b(star fmt(%9.4f)) se(par fmt(%9.3f)) ) 
			starlevels(* 0.1 ** 0.05 *** 0.01) 						
			keep(D)   
			coeflabel(D "Log avg. wage, non-policy") 
			stats(
				N Ncz Ncmp Tstd cmpXCZFE MonthFE, 
				fmt(%12.0gc) 
				label("Obs" "CZs" "Firms" "St. dev. market gap" "Company X CZ FEs" "Month from event FEs")
			)
			substitute({table} {threeparttable}) 	
			prefoot(\midrule) 
			postfoot(\bottomrule \bottomrule \end{tabular} \end{threeparttable} )			
	;
	#d cr	
	
*------------------------------------------------------------------------------------------------------------%	
* Table D11: Estimated spillover from large retailer VMWs, policy ind relative to rest of sample ind
*------------------------------------------------------------------------------------------------------------%	
	* Get NAICS codes for companies
	insheet using  "$data/cb/raw/[Project Name]_result1_8_ernaics.csv", clear
	tostring er_naics,gen(er_naics_str)
	replace er_naics_str=substr(er_naics_str,1,3)
	drop er_naics
	destring er_naics_str, gen(er_naics)
	contract cmp_company_code er_naics
	quietly bysort cmp_company_code:  gen dup = cond(_N==1,0,_n)
	tab dup
	drop if dup>1
	tempfile cmp_naics
	save `cmp_naics'
	
	* Load nonpolicy firm data
	use using "$data/cb/stacked_nonpolicy_firm_dataset.dta" if balanced_long==1, clear
	drop if trt_exp==4
	keep if inrange(etime, -12, 11)
	
	drop er_naics
	merge m:1 cmp_company_code using `cmp_naics' , keepusing(er_naics) 
		drop if _merge==2
		drop _merge
		
	gen policy_ind=0
	replace policy_ind=1 if er_naics==452 & (inrange(trt_exp,1,10) | inrange(trt_exp,17,22))
	replace policy_ind=1 if er_naics==454 & trt_exp==23
	replace policy_ind=1 if er_naics==722 & inrange(trt_exp,11,14)
		
	* Clean
	keep ln_avg_wage_exact cz etime trt_exp cmp_company_code poaching* feeder* sample_ind policy_ind estab_id super_gap T share_affected mw balanced_* months*
	
	* Indicator for post policy
	gen postperiod = etime>=0
	
	* Regress ------------------------------------------------------------------
	eststo clear

	* All
	preserve
	keep if sample_ind==1 
	qui sum T,d
	local std_T=round(r(sd),.001)
	
	egen T_std=std(T)
	replace T=T_std	
	
	eststo a1: reghdfe ln_avg_wage_exact c.T#1.postperiod#1.policy_ind c.T#1.postperiod 1.policy_ind#1.postperiod if balanced_short==1 & sample_ind==1 , absorb(i.cmp_company_code#i.cz#i.trt_exp i.cmp_company_code##i.trt_exp i.cz##i.trt_exp i.etime##i.trt_exp) cluster(cz)
	estadd local Tstd `std_T': a1
	distinct cz if e(sample) == 1
	estadd local Ncz `r(ndistinct)': a1
	distinct cmp_company_code if e(sample) == 1
	estadd local Ncmp `r(ndistinct)': a1	
	distinct cmp_company_code if e(sample) == 1 & policy_ind==1
	estadd local Ncmp_polind `r(ndistinct)': a1	
	estadd local cmpXCZFE "Y": a1
	estadd local MonthFE "Y": a1
	restore
	
	* Major
	preserve
	keep if share_affected > .3 & sample_ind==1
	qui sum T,d
	local std_T=round(r(sd),.001)
	
	egen T_std=std(T)
	replace T=T_std	
	
	eststo a2: reghdfe ln_avg_wage_exact c.T#1.postperiod#1.policy_ind c.T#1.postperiod 1.policy_ind#1.postperiod if balanced_short==1 & sample_ind==1 & share_affected>.3, absorb(i.cmp_company_code#i.cz#i.trt_exp i.cmp_company_code##i.trt_exp i.cz##i.trt_exp i.etime##i.trt_exp) cluster(cz)
	estadd local Tstd `std_T': a2
	distinct cz if e(sample) == 1
	estadd local Ncz `r(ndistinct)': a2
	distinct cmp_company_code if e(sample) == 1
	estadd local Ncmp `r(ndistinct)': a2	
	distinct cmp_company_code if e(sample) == 1 & policy_ind==1
	estadd local Ncmp_polind `r(ndistinct)': a2	
	estadd local cmpXCZFE "Y": a2
	estadd local MonthFE "Y": a2	
	restore 
	
	* $15
	preserve
	keep if  mw==15 & sample_ind==1
	qui sum T,d
	local std_T=round(r(sd),.001)
	
	egen T_std=std(T)
	replace T=T_std	

	eststo a3: reghdfe ln_avg_wage_exact c.T#1.postperiod#1.policy_ind c.T#1.postperiod 1.policy_ind#1.postperiod if balanced_short==1 & sample_ind==1 & mw==15, absorb(i.cmp_company_code#i.cz#i.trt_exp i.cmp_company_code##i.trt_exp i.cz##i.trt_exp i.etime##i.trt_exp) cluster(cz)
	estadd local Tstd `std_T': a3
	distinct cz if e(sample) == 1
	estadd local Ncz `r(ndistinct)': a3
	distinct cmp_company_code if e(sample) == 1
	estadd local Ncmp `r(ndistinct)': a3	
	distinct cmp_company_code if e(sample) == 1 & policy_ind==1
	estadd local Ncmp_polind `r(ndistinct)': a3	
	estadd local cmpXCZFE "Y": a3
	estadd local MonthFE "Y": a3
	restore 
	
	* Build table --------------------------------------------------------------
	#d ;
	esttab a* 
			using "$figures_tables/appendix/tabled11_spillover_policy_ind_heterogeneity.tex",  
			replace label fragment
			nolines  
			prehead("\begin{threeparttable} \begin{tabular}{lccc} \toprule \toprule & \multicolumn{3}{c}{Dep Var: Log average wage, non-policy} \\ Independent variables") 
			posthead("\cmidrule{2-4}") 
			booktabs								
			nonumbers 
			mtitles("All events" "Major events"  "\\$15 events") 
			collabels(none)  
			cells(b(star fmt(%9.5f)) se(par fmt(%9.5f)) ) 
			starlevels(* 0.1 ** 0.05 *** 0.01) 						
			keep(1.po*)   
			coeflabel(1.postperiod#1.policy_ind#c.T "Large retailer gap X 1(Post) X 1(Policy Ind)" 1.postperiod#c.T "Large retailer gap X 1(Post)" 1.policy_ind#1.postperiod "1(Post) X 1(Policy Ind)") 
			stats(
	N Ncz Ncmp Ncmp_polind Tstd cmpXCZFE MonthFE, 
				fmt(%12.0gc) 
				label("Obs" "CZs" "Firms" "Firms in large retailer industry" "St. dev. large retailer gap" "Company X CZ FEs" "Month from event FEs")
				)
			prefoot(\midrule) 
			postfoot(\bottomrule \bottomrule \end{tabular} \end{threeparttable} )
	;
	#d cr	
		
*------------------------------------------------------------------------------------------------------------%	
* Table D12: Estimated spillover from large retailer VMWs: Heterogeneity by employment share and ind same as policy or not
*------------------------------------------------------------------------------------------------------------%	
	* Get NAICS codes for companies
	insheet using  "$data/cb/raw/[Project Name]_result1_8_ernaics.csv", clear
	tostring er_naics,gen(er_naics_str)
	replace er_naics_str=substr(er_naics_str,1,3)
	drop er_naics
	destring er_naics_str, gen(er_naics)
	contract cmp_company_code er_naics
	quietly bysort cmp_company_code:  gen dup = cond(_N==1,0,_n)
	tab dup
	drop if dup>1
	tempfile cmp_naics
	save `cmp_naics'
	
	* Load nonpolicy firm data
	use if trt_exp!=4 & inrange(etime, -12, 11) & balanced_long==1 using "$data/cb/stacked_nonpolicy_firm_dataset.dta", clear
	
	* Clean
	gen employment_share_med = .
	levelsof trt_exp, local(exp)
	foreach experiment in `exp' {
		sum employment_share if trt_exp==`experiment', d
		replace employment_share_med = employment_share > `r(p50)' if trt_exp==`experiment'
		di `r(p50)'
	}
	
	drop er_naics
	merge m:1 cmp_company_code using `cmp_naics' , keepusing(er_naics) 
		drop if _merge==2
		drop _merge
		
	gen policy_ind=0
	replace policy_ind=1 if er_naics==452 & (inrange(trt_exp,1,10) | inrange(trt_exp,17,22))
	replace policy_ind=1 if er_naics==454 & trt_exp==23
	replace policy_ind=1 if er_naics==722 & inrange(trt_exp,11,14)
	
	keep ln_avg_wage_exact cz etime trt_exp cmp_company_code poaching* feeder* sample_ind estab_id T share_affected mw balanced_* months* employment_share_med employment_share employment_share_decile policy_ind
	
	* Indicator for post policy
	gen postperiod = etime>=0	
	
	* Regress ------------------------------------------------------------------
	eststo clear

	* All
	preserve
	keep if sample_ind==1 & employment_share_decile<7
	qui sum T,d
	local std_T=round(r(sd),.001)
	
	egen T_std=std(T)
	replace T=T_std	
	
	eststo a1: reghdfe ln_avg_wage_exact c.T#1.postperiod#1.policy_ind c.T#1.postperiod 1.policy_ind#1.postperiod if employment_share_decile<7 & sample_ind==1 , absorb(i.cmp_company_code#i.cz#i.trt_exp i.cmp_company_code##i.trt_exp i.cz##i.trt_exp i.etime##i.trt_exp) cluster(cz)
	estadd local Tstd `std_T': a1
	distinct cz if e(sample) == 1
	estadd local Ncz `r(ndistinct)': a1
	distinct cmp_company_code if e(sample) == 1
	estadd local Ncmp `r(ndistinct)': a1	
	sum employment_share if e(sample) == 1
	local temp: di %4.3f `r(mean)'
	estadd local MeanEmpShare `temp'
	estadd local cmpXCZFE "Y": a1
	estadd local MonthFE "Y": a1
	restore
	
	preserve
	keep if sample_ind==1 & employment_share_decile>=7
	qui sum T,d
	local std_T=round(r(sd),.001)
	
	egen T_std=std(T)
	replace T=T_std	

	eststo b1: reghdfe ln_avg_wage_exact c.T#1.postperiod#1.policy_ind c.T#1.postperiod 1.policy_ind#1.postperiod if employment_share_decile>=7 & sample_ind==1, absorb(i.cmp_company_code#i.cz#i.trt_exp i.cmp_company_code##i.trt_exp i.cz##i.trt_exp i.etime##i.trt_exp) cluster(cz)
	estadd local Tstd `std_T': b1
	distinct cz if e(sample) == 1
	estadd local Ncz `r(ndistinct)': b1
	distinct cmp_company_code if e(sample) == 1
	estadd local Ncmp `r(ndistinct)': b1	
	sum employment_share if e(sample) == 1
	local temp: di %4.3f `r(mean)'
	estadd local MeanEmpShare `temp'
	estadd local cmpXCZFE "Y": b1
	estadd local MonthFE "Y": b1
	restore
	
	* Major
	preserve
	keep if sample_ind==1 & share_affected > .3 & employment_share_decile<7
	qui sum T,d
	local std_T=round(r(sd),.001)
	
	egen T_std=std(T)
	replace T=T_std	

	eststo a2: reghdfe ln_avg_wage_exact c.T#1.postperiod#1.policy_ind c.T#1.postperiod 1.policy_ind#1.postperiod if employment_share_decile<7 & sample_ind==1 & share_affected > .3, absorb(i.cmp_company_code#i.cz#i.trt_exp i.cmp_company_code##i.trt_exp i.cz##i.trt_exp i.etime##i.trt_exp) cluster(cz)
	estadd local Tstd `std_T': a2
	distinct cz if e(sample) == 1
	estadd local Ncz `r(ndistinct)': a2
	distinct cmp_company_code if e(sample) == 1
	estadd local Ncmp `r(ndistinct)': a2	
	sum employment_share if e(sample) == 1
	local temp: di %4.3f `r(mean)'
	estadd local MeanEmpShare `temp'
	estadd local cmpXCZFE "Y": a2
	estadd local MonthFE "Y": a2
	restore
	
	preserve
	keep if sample_ind==1 & share_affected > .3 & employment_share_decile>=7
	qui sum T,d
	local std_T=round(r(sd),.001)
	
	egen T_std=std(T)
	replace T=T_std	
	
	eststo b2: reghdfe ln_avg_wage_exact c.T#1.postperiod#1.policy_ind c.T#1.postperiod 1.policy_ind#1.postperiod if employment_share_decile>=7 & sample_ind==1 & share_affected > .3, absorb(i.cmp_company_code#i.cz#i.trt_exp i.cmp_company_code##i.trt_exp i.cz##i.trt_exp i.etime##i.trt_exp) cluster(cz)
	estadd local Tstd `std_T': b2
	distinct cz if e(sample) == 1
	estadd local Ncz `r(ndistinct)': b2
	distinct cmp_company_code if e(sample) == 1
	estadd local Ncmp `r(ndistinct)': b2	
	sum employment_share if e(sample) == 1
	local temp: di %4.3f `r(mean)'
	estadd local MeanEmpShare `temp'
	estadd local cmpXCZFE "Y": b2
	estadd local MonthFE "Y": b2
	restore
	
	* $15
	preserve
	keep if sample_ind==1 & mw == 15 & employment_share_decile<7
	qui sum T,d
	local std_T=round(r(sd),.001)
	
	egen T_std=std(T)
	replace T=T_std	

	eststo a3: reghdfe ln_avg_wage_exact c.T#1.postperiod#1.policy_ind c.T#1.postperiod 1.policy_ind#1.postperiod if employment_share_decile<7 & sample_ind==1 & mw == 15, absorb(i.cmp_company_code#i.cz#i.trt_exp i.cmp_company_code##i.trt_exp i.cz##i.trt_exp i.etime##i.trt_exp) cluster(cz)
	estadd local Tstd `std_T': a3
	distinct cz if e(sample) == 1
	estadd local Ncz `r(ndistinct)': a3
	distinct cmp_company_code if e(sample) == 1
	estadd local Ncmp `r(ndistinct)': a3	
	sum employment_share if e(sample) == 1
	local temp: di %4.3f `r(mean)'
	estadd local MeanEmpShare `temp'
	estadd local cmpXCZFE "Y": a3
	estadd local MonthFE "Y": a3
	restore
	
	preserve
	keep if sample_ind==1 & mw == 15 & employment_share_decile>=7
	qui sum T,d
	local std_T=round(r(sd),.001)
	
	egen T_std=std(T)
	replace T=T_std	

	eststo b3: reghdfe ln_avg_wage_exact c.T#1.postperiod#1.policy_ind c.T#1.postperiod 1.policy_ind#1.postperiod if employment_share_decile>=7 & sample_ind==1 & mw == 15, absorb(i.cmp_company_code#i.cz#i.trt_exp i.cmp_company_code##i.trt_exp i.cz##i.trt_exp i.etime##i.trt_exp) cluster(cz)
	estadd local Tstd `std_T': b3
	distinct cz if e(sample) == 1
	estadd local Ncz `r(ndistinct)': b3
	distinct cmp_company_code if e(sample) == 1
	estadd local Ncmp `r(ndistinct)': b3	
	sum employment_share if e(sample) == 1
	local temp: di %4.3f `r(mean)'
	estadd local MeanEmpShare `temp'
	estadd local cmpXCZFE "Y": b3
	estadd local MonthFE "Y": b3
	restore
	
	* Build table --------------------------------------------------------------
	#d ;
	esttab a* b*
			using "$figures_tables/appendix/tabled12_spillover_emp_share_policy_ind_heterogeneity.tex",  
			replace label fragment
			nolines  
			prehead("\begin{threeparttable} \begin{tabular}{lcccccc} \toprule \toprule & \multicolumn{6}{c}{Dep Var: Log average wage, non-policy} \\ & \multicolumn{3}{c}{Low Emp. Share} & \multicolumn{3}{c}{High Emp. Share} \\ Independent variables") 
			posthead(\cmidrule(lr){2-4} \cmidrule(lr){5-7}) 
			booktabs								
			nonumbers 
			mtitles("All events" "Major events"  "\\$15 events" "All events" "Major events"  "\\$15 events") 
			collabels(none)  
			cells(b(star fmt(%9.5f)) se(par fmt(%9.5f)) ) 
			starlevels(* 0.1 ** 0.05 *** 0.01) 						
			keep(1.po*)   
			coeflabel(1.postperiod#1.policy_ind#c.T "Large retailer gap X 1(Post) X 1(Policy Ind)" 1.postperiod#c.T "Large retailer gap X 1(Post)" 1.policy_ind#1.postperiod "1(Post) X 1(Policy Ind)") 
			stats(
	N Ncz Ncmp Tstd MeanEmpShare cmpXCZFE MonthFE, 
				fmt(%12.0gc) 
				label("Obs" "CZs" "Firms" "St. dev. large retailer gap" "Mean policy emp. share" "Company X CZ FEs" "Month from event FEs")
				)
			prefoot(\midrule) 
			postfoot(\bottomrule \bottomrule \end{tabular} \end{threeparttable} )
	;
	#d cr
	
*------------------------------------------------------------------------------------------------------------%	
* Table D13: Estimated spillover from large retailer VMWs, policy ind relative to rest of sample ind, market gap
*------------------------------------------------------------------------------------------------------------%	
	* Get NAICS codes for companies
	insheet using  "$data/cb/raw/[Project Name]_result1_8_ernaics.csv", clear
	tostring er_naics,gen(er_naics_str)
	replace er_naics_str=substr(er_naics_str,1,3)
	drop er_naics
	destring er_naics_str, gen(er_naics)
	contract cmp_company_code er_naics
	quietly bysort cmp_company_code:  gen dup = cond(_N==1,0,_n)
	tab dup
	drop if dup>1
	tempfile cmp_naics
	save `cmp_naics'
	
	* Load nonpolicy firm data
	use using "$data/cb/stacked_nonpolicy_firm_dataset.dta" if balanced_long==1, clear
	drop if trt_exp==4
	keep if inrange(etime, -12, 11)
	
	drop er_naics
	merge m:1 cmp_company_code using `cmp_naics' , keepusing(er_naics) 
		drop if _merge==2
		drop _merge
		
	gen policy_ind=0
	replace policy_ind=1 if er_naics==452 & (inrange(trt_exp,1,10) | inrange(trt_exp,17,22))
	replace policy_ind=1 if er_naics==454 & trt_exp==23
	replace policy_ind=1 if er_naics==722 & inrange(trt_exp,11,14)
		
	* Clean
	keep ln_avg_wage_exact cz etime trt_exp cmp_company_code poaching* feeder* sample_ind policy_ind estab_id super_gap T share_affected mw balanced_* months*
	
	* Indicator for post policy
	gen postperiod = etime>=0
	
	* Regress ------------------------------------------------------------------
	eststo clear

	* All
	preserve
	keep if sample_ind==1 
	qui sum super_gap,d
	local std_T=round(r(sd),.001)
	
	egen sg_std=std(super_gap)
	replace T=sg_std	
	
	eststo a1: reghdfe ln_avg_wage_exact c.T#1.postperiod#1.policy_ind c.T#1.postperiod 1.policy_ind#1.postperiod if balanced_short==1 & sample_ind==1 , absorb(i.cmp_company_code#i.cz#i.trt_exp i.cmp_company_code##i.trt_exp i.cz##i.trt_exp i.etime##i.trt_exp) cluster(cz)
	estadd local Tstd `std_T': a1
	distinct cz if e(sample) == 1
	estadd local Ncz `r(ndistinct)': a1
	distinct cmp_company_code if e(sample) == 1
	estadd local Ncmp `r(ndistinct)': a1	
	estadd local cmpXCZFE "Y": a1
	estadd local MonthFE "Y": a1
	restore
	
	* Major
	preserve
	keep if share_affected > .3 & sample_ind==1
	qui sum super_gap,d
	local std_T=round(r(sd),.001)
	
	egen sg_std=std(super_gap)
	replace T=sg_std	
	
	eststo a2: reghdfe ln_avg_wage_exact c.T#1.postperiod#1.policy_ind c.T#1.postperiod 1.policy_ind#1.postperiod if balanced_short==1 & sample_ind==1 & share_affected>.3, absorb(i.cmp_company_code#i.cz#i.trt_exp i.cmp_company_code##i.trt_exp i.cz##i.trt_exp i.etime##i.trt_exp) cluster(cz)
	estadd local Tstd `std_T': a2
	distinct cz if e(sample) == 1
	estadd local Ncz `r(ndistinct)': a2
	distinct cmp_company_code if e(sample) == 1
	estadd local Ncmp `r(ndistinct)': a2	
	estadd local cmpXCZFE "Y": a2
	estadd local MonthFE "Y": a2	
	restore 
	
	* $15
	preserve
	keep if  mw==15 & sample_ind==1
	qui sum super_gap,d
	local std_T=round(r(sd),.001)
	
	egen sg_std=std(super_gap)
	replace T=sg_std	

	eststo a3: reghdfe ln_avg_wage_exact c.T#1.postperiod#1.policy_ind c.T#1.postperiod 1.policy_ind#1.postperiod if balanced_short==1 & sample_ind==1 & mw==15, absorb(i.cmp_company_code#i.cz#i.trt_exp i.cmp_company_code##i.trt_exp i.cz##i.trt_exp i.etime##i.trt_exp) cluster(cz)
	estadd local Tstd `std_T': a3
	distinct cz if e(sample) == 1
	estadd local Ncz `r(ndistinct)': a3
	distinct cmp_company_code if e(sample) == 1
	estadd local Ncmp `r(ndistinct)': a3	
	estadd local cmpXCZFE "Y": a3
	estadd local MonthFE "Y": a3
	restore 
	
	* Build table --------------------------------------------------------------
	#d ;
	esttab a* 
			using "$figures_tables/appendix/tabled13_sg_spillover_policy_ind_heterogeneity.tex",  
			replace label fragment
			nolines  
			prehead("\begin{threeparttable} \begin{tabular}{lccc} \toprule \toprule & \multicolumn{3}{c}{Dep Var: Log average wage, non-policy} \\ Independent variables") 
			posthead("\cmidrule{2-4}") 
			booktabs								
			nonumbers 
			mtitles("All events" "Major events"  "\\$15 events") 
			collabels(none)  
			cells(b(star fmt(%9.5f)) se(par fmt(%9.5f)) ) 
			starlevels(* 0.1 ** 0.05 *** 0.01) 						
			keep(1.po*)   
			coeflabel(1.postperiod#1.policy_ind#c.T "Market gap X 1(Post) X 1(Policy Ind)" 1.postperiod#c.T "Market gap X 1(Post)" 1.policy_ind#1.postperiod "1(Post) X 1(Policy Ind)") 
			stats(
	N Ncz Ncmp Tstd cmpXCZFE MonthFE, 
				fmt(%12.0gc) 
				label("Obs" "CZs" "Firms" "St. dev. large retailer gap" "Company X CZ FEs" "Month from event FEs")
				)
			prefoot(\midrule) 
			postfoot(\bottomrule \bottomrule \end{tabular} \end{threeparttable} )
	;
	#d cr	

*------------------------------------------------------------------------------------------------------------%	
* Compute estimates for Figure 10
*------------------------------------------------------------------------------------------------------------%	
	* Get NAICS codes for companies
	insheet using  "$data/cb/raw/[Project Name]_result1_8_ernaics.csv", clear
	tostring er_naics,gen(er_naics_str)
	replace er_naics_str=substr(er_naics_str,1,3)
	drop er_naics
	destring er_naics_str, gen(er_naics)
	contract cmp_company_code er_naics
	quietly bysort cmp_company_code:  gen dup = cond(_N==1,0,_n)
	tab dup
	drop if dup>1
	tempfile cmp_naics
	save `cmp_naics'
	
* Load nonpolicy firm data

	use using "$data/cb/stacked_nonpolicy_firm_dataset.dta" if balanced_long==1, clear
	drop er_naics
	gen pos_flows_estab = (feeder_estab == 1 | poaching_estab == 1)

	*keep if sample_ind==1

	drop if trt_exp==4
	keep if inrange(etime, -12, 11)

	merge m:1 cmp_company_code using `cmp_naics' , keepusing(er_naics) 
		drop if _merge==2
		drop _merge
		
	gen policy_ind=0
	replace policy_ind=1 if er_naics==452 & (inrange(trt_exp,1,10) | inrange(trt_exp,17,22))
	replace policy_ind=1 if er_naics==454 & trt_exp==23
	replace policy_ind=1 if er_naics==722 & inrange(trt_exp,11,14)
			
	* Clean before merge
	rename ln_avg_wage_exact ln_wage_other
	rename avg_wage_exact avg_wage_exact_other
	rename tot_emp tot_emp_other
	keep ln_wage_other avg_wage_exact_other tot_emp_other cz etime trt_exp cmp_company_code poaching* feeder* sample_ind estab_id T share_affected mw balanced_* months* employment_share_q_all_decile policy_ind pos_flows_estab er_naics

	* Merge with policy firm data
	merge m:1 cz etime trt_exp using "$data/cb/stacked_policy_firm_dataset.dta", nogen keep (3) keepusing(ln_avg_wage_exact avg_wage_exact tot_emp)

	global wage ln_avg_wage_exact
	la var ln_avg_wage_exact "log average hourly wage"
	
	* Indicator for post policy
	gen postperiod = etime>=0
	
	gen high_emp_share=employment_share_q_all_decile>=7
	
	gen pol_high_emp=(high_emp_share & policy_ind==1)
	gen sample_ind_high_emp=(high_emp_share & sample_ind==1)
	gen pos_flows_high_emp=(high_emp_share & pos_flows_estab==1)
	
	gen all=(trt_exp>0)
	gen major=(share_affected>.3)
	gen mw15=(mw==15)
	
	* Regress ------------------------------------------------------------------
	foreach exp_group in all major mw15{
	foreach type in policy_ind sample_ind pos_flows_estab high_emp_share pol_high_emp sample_ind_high_emp pos_flows_high_emp{
	
	* All
	preserve
	keep if `exp_group'==1
	keep if `type'==1
	qui sum T,d
	local std_T=round(r(sd),.001)
	
	egen T_std=std(T)
	replace T=T_std	
	
	* Generate treatment variable
	gen D = T*postperiod

	ivreghdfe ln_wage_other ($wage = D), absorb( i.cmp_company_code#i.cz#i.trt_exp i.cmp_company_code##i.trt_exp i.cz##i.trt_exp i.etime##i.trt_exp) cluster(cz) first
		parmest, saving("$figures_tables/reg_output/cwe_estimates_`exp_group'_`type'" ,replace)
		
	keep if e(sample)==1
	gen tot_wage_bill_other=tot_emp_other * avg_wage_exact_other
	gen tot_wage_bill_policy = tot_emp * avg_wage_exact	
	egen tot_wage_bill_all_other=sum(tot_wage_bill_other),by(cz trt_exp etime)		
	gen tot_wage_bill_all=tot_wage_bill_all_other+tot_wage_bill_policy
	egen tot_emp_all_other = sum(tot_emp_other),by(cz trt_exp etime)		
	gen tot_emp_all = tot_emp + tot_emp_all_other
	
	* Final employment share measure is numerator divided by denominator
	gen np_wage_bill_share_monthly=tot_wage_bill_other/tot_wage_bill_all
	gen pol_wage_bill_share_monthly=tot_wage_bill_policy/tot_wage_bill_all
	gen np_emp_share_monthly = tot_emp_other/tot_emp_all
	gen pol_emp_share_monthly = tot_emp/tot_emp_all
	
	* Create super gap and wage bill share measure	
	* Specify start and end dates for gap and share measures
	qui replace np_wage_bill_share_monthly=. if etime>=0 	
	qui egen np_wage_bill_share=mean(np_wage_bill_share_monthly), by(cz trt_exp) 
	
	qui replace pol_wage_bill_share_monthly=. if etime>=0 	
	qui egen pol_wage_bill_share=mean(pol_wage_bill_share_monthly), by(cz trt_exp) 
	
	qui replace np_emp_share_monthly=. if etime>=0
	qui egen np_emp_share=mean(np_emp_share_monthly), by(cz trt_exp) 
	
	qui replace pol_emp_share_monthly=. if etime>=0
	qui egen pol_emp_share=mean(pol_emp_share_monthly), by(cz trt_exp) 
	
	qui sum np_wage_bill_share
	local np_`exp_group'_`type'=r(mean)
	di `np_`exp_group'_`type''
	qui sum pol_wage_bill_share
	local p_`exp_group'_`type'=r(mean)	
	di `p_`exp_group'_`type''
	gen r_wage_bill_share = pol_wage_bill_share/(1-np_wage_bill_share)
	qui sum r_wage_bill_share	
	local r_`exp_group'_`type'=r(mean)
	di `r_`exp_group'_`type''
	qui sum np_emp_share
	local npe_`exp_group'_`type'=r(mean)
	qui sum pol_emp_share
	local pe_`exp_group'_`type'=r(mean)	
	
	restore
	}
	}
	

	clear 
	set obs 0
	gen exp_group = ""
	gen type = ""
	gen pol_wage_bill_share = .
	gen np_wage_bill_share = .
	gen wb_share_ratio = .
	gen pol_emp_share = .
	gen np_emp_share = .
		
	foreach exp_group in all major mw15{
	foreach type in policy_ind sample_ind pos_flows_estab high_emp_share pol_high_emp sample_ind_high_emp pos_flows_high_emp{

		cap append using "$figures_tables/reg_output/cwe_estimates_`exp_group'_`type'" // recursively appen datasets
		
		*Name variables
		replace exp_group 	= "`exp_group'" 	if exp_group==""
		replace type 		= "`type'" 			if type==""
		replace pol_wage_bill_share = `p_`exp_group'_`type'' if pol_wage_bill_share==.
		replace np_wage_bill_share = `np_`exp_group'_`type'' if np_wage_bill_share==.
		replace wb_share_ratio = `r_`exp_group'_`type'' if wb_share_ratio==.
		replace pol_emp_share = `pe_`exp_group'_`type'' if pol_emp_share==.
		replace np_emp_share = `npe_`exp_group'_`type'' if np_emp_share==.
		}
	}
	
	*%-----------------------------------%
	*%----------  Save dataset ----------%
	*%-----------------------------------%
	save "$figures_tables/cwe_estimates_pooled_for_plotting.dta", replace
	outsheet using	"$figures_tables/estimates/cwe_estimates_pooled_for_plotting.csv", comma replace			

*------------------------------------------------------------------------------------------------------------%	
* Compute estimates by experiment for Figure 10
*------------------------------------------------------------------------------------------------------------%	
	* Get NAICS codes for companies
	insheet using  "$data/cb/raw/[Project Name]_result1_8_ernaics.csv", clear
	tostring er_naics,gen(er_naics_str)
	replace er_naics_str=substr(er_naics_str,1,3)
	drop er_naics
	destring er_naics_str, gen(er_naics)
	contract cmp_company_code er_naics
	quietly bysort cmp_company_code:  gen dup = cond(_N==1,0,_n)
	tab dup
	drop if dup>1
	tempfile cmp_naics
	save `cmp_naics'
	
* Load nonpolicy firm data

	use using "$data/cb/stacked_nonpolicy_firm_dataset.dta" if balanced_long==1, clear
	
	gen pos_flows_estab = (feeder_estab == 1 | poaching_estab == 1)

	*keep if sample_ind==1

	drop if trt_exp==4
	keep if inrange(etime, -12, 11)

	drop er_naics
	merge m:1 cmp_company_code using `cmp_naics' , keepusing(er_naics) 
		drop if _merge==2
		drop _merge
		
	gen policy_ind=0
	replace policy_ind=1 if er_naics==452 & (inrange(trt_exp,1,10) | inrange(trt_exp,17,22))
	replace policy_ind=1 if er_naics==454 & trt_exp==23
	replace policy_ind=1 if er_naics==722 & inrange(trt_exp,11,14)	
			
	* Clean before merge
	rename ln_avg_wage_exact ln_wage_other
	rename avg_wage_exact avg_wage_exact_other
	rename tot_emp tot_emp_other
	keep ln_wage_other avg_wage_exact_other tot_emp_other cz etime trt_exp cmp_company_code poaching* feeder* sample_ind estab_id T share_affected mw balanced_* months* employment_share_q_all_decile policy_ind pos_flows_estab

	* Merge with policy firm data
	merge m:1 cz etime trt_exp using "$data/cb/stacked_policy_firm_dataset.dta", nogen keep (3) keepusing(ln_avg_wage_exact avg_wage_exact tot_emp)

	global wage ln_avg_wage_exact
	la var ln_avg_wage_exact "log average hourly wage"
	
	* Indicator for post policy
	gen postperiod = etime>=0
	
	gen high_emp_share=employment_share_q_all_decile>=7
	
	gen pol_high_emp=(high_emp_share & policy_ind==1)
	gen sample_ind_high_emp=(high_emp_share & sample_ind==1)
	gen pos_flows_high_emp=(high_emp_share & pos_flows_estab==1)
	
	* Regress ------------------------------------------------------------------
	
	levelsof trt_exp, local(exp)
 
	foreach experiment in `exp' {

	foreach type in policy_ind sample_ind pos_flows_estab high_emp_share pol_high_emp sample_ind_high_emp pos_flows_high_emp{
	
	* All
	preserve
	keep if trt_exp==`experiment'
	keep if `type'==1
	qui sum T,d
	local std_T=round(r(sd),.001)
	
	egen T_std=std(T)
	replace T=T_std	
	
	* Generate treatment variable
	gen D = T*postperiod

	ivreghdfe ln_wage_other ($wage = D), absorb(i.cmp_company_code#i.cz i.cmp_company_code i.cz i.etime) cluster(cz) first
		parmest, saving("$figures_tables/reg_output/cwe_estimates_exp`experiment'_`type'" ,replace)
		
	keep if e(sample)==1
	gen tot_wage_bill_other=tot_emp_other * avg_wage_exact_other
	gen tot_wage_bill_policy = tot_emp * avg_wage_exact	
	egen tot_wage_bill_all_other=sum(tot_wage_bill_other),by(cz trt_exp etime)		
	gen tot_wage_bill_all=tot_wage_bill_all_other+tot_wage_bill_policy
	egen tot_emp_all_other = sum(tot_emp_other),by(cz trt_exp etime)		
	gen tot_emp_all = tot_emp + tot_emp_all_other
	
	* Final employment share measure is numerator divided by denominator
	gen np_wage_bill_share_monthly=tot_wage_bill_other/tot_wage_bill_all
	gen pol_wage_bill_share_monthly=tot_wage_bill_policy/tot_wage_bill_all
	gen np_emp_share_monthly = tot_emp_other/tot_emp_all
	gen pol_emp_share_monthly = tot_emp/tot_emp_all
	
	* Create super gap and wage bill share measure	
	* Specify start and end dates for gap and share measures
	qui replace np_wage_bill_share_monthly=. if etime>=0 	
	qui egen np_wage_bill_share=mean(np_wage_bill_share_monthly), by(cz trt_exp) 
	
	qui replace pol_wage_bill_share_monthly=. if etime>=0 	
	qui egen pol_wage_bill_share=mean(pol_wage_bill_share_monthly), by(cz trt_exp) 
	
	qui replace np_emp_share_monthly=. if etime>=0
	qui egen np_emp_share=mean(np_emp_share_monthly), by(cz trt_exp) 
	
	qui replace pol_emp_share_monthly=. if etime>=0
	qui egen pol_emp_share=mean(pol_emp_share_monthly), by(cz trt_exp) 
	
	qui sum np_wage_bill_share
	local np_`experiment'_`type'=r(mean)
	di `np_`experiment'_`type''
	qui sum pol_wage_bill_share
	local p_`experiment'_`type'=r(mean)	
	di `p_`experiment'_`type''
	gen r_wage_bill_share = pol_wage_bill_share/(1-np_wage_bill_share)
	qui sum r_wage_bill_share	
	local r_`experiment'_`type'=r(mean)
	di `r_`experiment'_`type''
	qui sum np_emp_share
	local npe_`experiment'_`type'=r(mean)
	qui sum pol_emp_share
	local pe_`experiment'_`type'=r(mean)	
	
	restore
	}
	}
	
	*use using "$data/cb/events.dta" if eventid!=4, clear
	
	*levelsof eventid, local(exp)
 
	clear 
	set obs 0
	gen experiment = ""
	gen type = ""
	gen pol_wage_bill_share = .
	gen np_wage_bill_share = .
	gen wb_share_ratio = .
	gen pol_emp_share = .
	gen np_emp_share = .
		
	foreach experiment in `exp' {

	foreach type in policy_ind sample_ind pos_flows_estab high_emp_share pol_high_emp sample_ind_high_emp pos_flows_high_emp{

		cap append using "$figures_tables/reg_output/cwe_estimates_exp`experiment'_`type'" // recursively appen datasets
		
		*Name variables
		replace experiment 	= "`experiment'" 	if experiment==""
		replace type 		= "`type'" 			if type==""
		replace pol_wage_bill_share = `p_`experiment'_`type'' if pol_wage_bill_share==.
		replace np_wage_bill_share = `np_`experiment'_`type'' if np_wage_bill_share==.
		replace wb_share_ratio = `r_`experiment'_`type'' if wb_share_ratio==.
		replace pol_emp_share = `pe_`experiment'_`type'' if pol_emp_share==.
		replace np_emp_share = `npe_`experiment'_`type'' if np_emp_share==.
		}
	}
	
	destring experiment, replace
	
	*%-----------------------------------%
	*%----------  Save dataset ----------%
	*%-----------------------------------%
	save "$figures_tables/cwe_estimates_experiment_level_for_plotting.dta", replace			
	outsheet using "$figures_tables/estimates/cwe_estimates_experiment_level_for_plotting.csv", comma replace		
